import psycopg2
from sqlalchemy import create_engine,text

conn = psycopg2.connect(
    dbname="vastbase",
    user="zxs",
    password="Aa123456",
    host="172.16.55.184",
    port="5432"
)


# 配置数据库连接信息
db_config = {
    'user': 'zxs',
    'password': 'Aa123456',
    'host': '172.16.55.184',
    'port': '5432',
    'database': 'vastbase'
}

# 使用psycopg2创建数据库连接
conn = psycopg2.connect(**db_config)

# 使用SQLAlchemy创建数据库引擎
engine = create_engine('postgresql+psycopg2://', creator=lambda: conn)
# 执行SQL查询
with engine.connect() as connection:
    connection.execute("create if not exists table t4(name varchar(1000))")
    # connection.execute("insert into t4 values('zhangxishun')")
    result = connection.execute(text('SELECT * FROM t4;'))
    # 处理查询结果
    for row in result:
        print(row)

# 关闭连接
conn.close()

